/*
 * $Id: eth.c,v 1.1 2006-06-02 16:21:58 bacon Exp $
 */

#include <xp/net/eth.h>
#include <xp/net/sck.h>

xp_eth_t* xp_eth_open (const char* dev)
{
	xp_eth_t* eth;

	eth = (xp_eth_t*) xp_malloc (xp_sizeof(xp_eth_t));
	if (eth == XP_NULL) return XP_NULL;

	eth->hnd = xp_sckopen (PF_PACKET, SOCK_RAW, xp_hton16(ETH_P_ALL));
	if (eth->hnd == -1)
	{
		xp_free (eth);
		return XP_NULL;
	}

	xp_mstrxcpy (ifr.ifr_name, xp_countof(ifr.ifr_name), device);
	if (ioctl(eth->hnd, SIOCGIFINDEX, &ifindex) == -1)
	{
		xp_free (eth);
		return XP_NULL;
	}

	eth->sll.sll_family = AF_PACKET;
	eth->sll.sll_ifindex = ifindex;
	return eth;
}

int xp_eth_close (xp_eth_t* eth)
{
	xp_free (eth);
	return 0;
}

xp_ssize_t xp_eth_send (xp_eth_t* eth, const void* msg, xp_size_t len)
{
	return xp_scksendto (eth->hnd, msg, len, 0, 
		(struct sockaddr*)&eth->sll, xp_sizeof(eth->sll));
}

/*
int xp_eth_setadr ()
{
}
int xp_eth_getadr ()
{
}
*/
